﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Maxleaf.EDI.API.Contract.Admin.Parameters;
using Maxleaf.EDI.Domain;
using Maxleaf.EDI.Domain.EDI;

namespace Maxleaf.EDI.Core.Handlers.QueryHandlers
{
    public class AuthenticateAdminQueryHandler : IQueryHandler<AuthenticateParameters,AuthenticateResult>
    {
        public AuthenticateAdminQueryHandler()
        {
        }

        public AuthenticateResult Handle(AuthenticateParameters parameters)
        {
                if (string.IsNullOrEmpty(parameters.UserName))
                {
                    return new AuthenticateResult() { IsAuthorized = false };
                }

                var password = System.Configuration.ConfigurationManager.AppSettings[string.Format("A:{0}", parameters.UserName)];
                var isAuthorized = password.Equals(parameters.Password,StringComparison.InvariantCultureIgnoreCase);
                
                return new AuthenticateResult() { IsAuthorized = isAuthorized};
        }
    }
}
